<template>
	<!-- 提现 -->
	<view class="page">
		<view class="card">
			<view class="title">提现余额</view>
			<view class="price">
				<input class="input" type="digit" v-model="form.amount" @blur="blur" />
				<text @click="form.amount=amount">全部提现</text>
			</view>
			<view class="all_price">可提现：{{$fn.twoToFixed(amount)}}</view>
		</view>
		<view class="card">
			<view class="select">
				<view class="select_item" @click="payType='1'">
					<image v-if="payType=='1'" class="radio" src="/pages/my/static/radio-a.png" />
					<image v-else class="radio" src="/pages/my/static/radio.png" />
					微信、支付宝
				</view>
				<view class="select_item" @click="payType='2'">
					<image v-if="payType=='2'" class="radio" src="/pages/my/static/radio-a.png" />
					<image v-else class="radio" src="/pages/my/static/radio.png" />
					银行卡
				</view>
			</view>

			<view class="main" v-if="payType=='1'">
				<c-upLoadImgs format="string" :file.sync="form.wechatAliImages" />
			</view>
			<view v-else>
				<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" labelWidth="auto">
					<u-form-item label="姓名" prop="cardholderName" borderBottom>
						<u--input v-model="form.cardholderName" placeholder="请输入持卡人姓名" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="银行" prop="bankName" borderBottom>
						<u--input v-model="form.bankName" placeholder="请输入所属银行" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="银行卡号" prop="bankCardNumber" borderBottom>
						<u--input v-model="form.bankCardNumber" placeholder="请输入银行卡卡号" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<!-- <u-form-item label="银行预留手机号" prop="bankNumber" borderBottom>
						<u--input v-model="form.bankNumber" placeholder="请输入手机号码" border="none"
							inputAlign="right"></u--input>
					</u-form-item> -->
				</u--form>
			</view>
		</view>

		<view class="btns">
			<view class="btn1" @click="$fn.jumpPage('/pages/my/pages/withdrawRecord')">提现记录</view>
			<view class="btn2" @click="submit">提现</view>
		</view>
		<c-3TimeTips img="/static/common/icon-success.png" :show.sync="showTips" @back="back" />
	</view>
</template>

<script>
	export default {
		name: "withdraw",
		data() {
			return {
				amount: 0,
				showTips: false,
				price: 0,
				payType: '1',
				form: {
					amount: 0,
					cardholderName: '',
					bankName: '',
					bankCardNumber: '',
					// bankNumber: '',
					wechatAliImages: ''
				},
				rules: {
					cardholderName: {
						type: 'string',
						required: true,
						message: '请输入持卡人姓名',
						trigger: ['blur', 'change']
					},
					bankName: {
						type: 'string',
						required: true,
						message: '请输入所属银行',
						trigger: ['blur', 'change']
					},
					bankCardNumber: [{
						type: 'string',
						required: true,
						message: '请输入银行卡卡号',
						trigger: ['blur', 'change']
					}],
					bankNumber: [{
						type: 'string',
						required: true,
						message: '请输入手机号码',
						trigger: ['blur', 'change']
					}, { // 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// uni.$u.test.mobile()就是返回true或者false的
							return uni.$u.test.mobile(value);
						},
						message: '手机号码不正确',
						// 触发器可以同时用blur和change
						trigger: ['change', 'blur'],
					}],
				}
			};
		},
		onLoad(option) {
			uni.setNavigationBarColor({
				backgroundColor: '#FFFFFF',
				frontColor: '#000000'
			})
			this.amount = option.amount
		},
		onShow() {},
		methods: {
			// 输入金额失焦
			blur() {
				console.log(this.price, '失去焦点');
				if (!this.price) this.price = 0
			},
			// 提交
			submit() {
				console.log('this.form', this.form);
				if (this.form.amount <= 0 || !this.form.amount) {
					return uni.showToast({
						icon: 'none',
						title: '提现金额不能为 0'
					})
				}

				if (this.payType == 1) {
					if (!this.form.wechatAliImages) {
						return uni.showToast({
							icon: 'none',
							title: '请上传微信支付宝收款码'
						})
					}

					this.$api.applicationWithdraw(this.form).then(res => {
						console.log('提现成功1', res);
						this.showTips = true

					})
				} else {
					this.$refs.uForm.validate().then(res => {
						this.$api.applicationWithdraw(this.form).then(res => {
							console.log('提现成功2', res);
							this.showTips = true
						})
						// uni.$u.toast('校验通过')
					}).catch(errors => {
						// uni.$u.toast('校验失败')
					})
				}
			},
			back() {
				uni.navigateBack()
			}

		}
	};
</script>

<style>
	page {
		background: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.card {
		width: 702rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin: 24rpx auto 0;
		padding: 24rpx;
		box-sizing: border-box;
	}

	.title {
		font-size: 28rpx;
		color: #1A1A1A;
	}

	.price {
		display: flex;
		align-items: center;
		gap: 20rpx;
		font-size: 28rpx;
		color: #EF4630;
		padding: 24rpx 0;
		margin: 34rpx 0;
		border-bottom: 1rpx solid #999999;

		.input {
			flex: 1;
			height: 80rpx;
			font-weight: bold;
			font-size: 80rpx;
			color: #1A1A1A;
		}
	}

	.all_price {
		font-weight: 400;
		font-size: 28rpx;
		color: #666666;
	}

	.select {
		display: flex;
		align-items: center;
		gap: 80rpx;

		.select_item {
			display: flex;
			align-items: center;
			gap: 16rpx;
			font-size: 32rpx;
			color: #1A1A1A;

			.radio {
				width: 28rpx;
				height: 28rpx;
			}
		}
	}

	.main {
		margin-top: 32rpx;
	}

	.btns {
		display: flex;
		align-items: center;
		position: fixed;
		bottom: 68rpx;
		left: 50%;
		transform: translateX(-50%);
		font-size: 32rpx;

		.btn1 {
			width: 342rpx;
			height: 96rpx;
			background: #E6E6E6;
			border-radius: 48rpx 0rpx 0rpx 48rpx;
			color: #262626;
			text-align: center;
			line-height: 96rpx;
		}

		.btn2 {
			width: 344rpx;
			height: 96rpx;
			background: linear-gradient(141deg, #F0A367 0%, #EF4630 100%);
			border-radius: 0rpx 48rpx 48rpx 0rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 96rpx;
		}
	}
</style>